package com.fdb.efp.flow.api.rest;

import java.util.List;
import java.util.Map;

import com.fdb.basic.framework.core.constant.PubConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fdb.efp.e4a.service.facade.SRoleDataRuleService;
import com.fdb.efp.flow.service.facade.BizFlowRouteService;
import com.fdb.efp.flow.service.vo.BizFlowRouteVO;
import com.fdb.basic.framework.core.constant.DataRuleType;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.core.log.LogManager;
import com.fdb.basic.framework.web.controller.AbstractController;

@RestController
@RequestMapping("/api")
public class BizFlowRouteController extends AbstractController  {

	@Autowired
	@Qualifier("bizFlowRouteService")
	private BizFlowRouteService bizFlowRouteService;

	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;

	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/biz/flow/routes", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<BizFlowRouteVO>> queryBizFlowRouteAll(
			@RequestBody BizFlowRouteVO vo) {		

		LogManager.info(vo.getBizFlowId(), bizFlowRouteService, "queryAll");

		//List<BizFlowRouteVO> outputVo = this.executeQueryList("queryAll", bizFlowRouteService, new Object[]{vo});

		List<BizFlowRouteVO> outputVo = null;

		// 根据用户角色获取用户权限方案
		//Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		//DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		DataRuleType dataRuleType = DataRuleType.getDataRuleType("01");
		switch (dataRuleType) {
		case Owner:
			outputVo = bizFlowRouteService.queryAllOwner(vo);
			break;
		case CurrOrg:
			outputVo = bizFlowRouteService.queryAllCurrOrg(vo);
			break;
		case CurrDownOrg:
			outputVo = bizFlowRouteService.queryAllCurrDownOrg(vo);
			break;
		default:
			outputVo = bizFlowRouteService.queryAllOwner(vo);
			break;
		}

		return getResponseData(outputVo);

	}

	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/biz/flow/route/{bizRouteId}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<BizFlowRouteVO> queryByPk(@PathVariable("bizRouteId") String bizRouteId) {		
		BizFlowRouteVO inVo = new BizFlowRouteVO();
		inVo.setBizRouteId(bizRouteId);
		BizFlowRouteVO outputVo = bizFlowRouteService.queryByPk(inVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键删除信息
	 * @param bizFlowRoute
	 * @return
	 */
	@RequestMapping(value="/biz/flow/route", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody BizFlowRouteVO inBizFlowRouteVo) {		
		int outputVo = bizFlowRouteService.deleteByPk(inBizFlowRouteVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键更新信息
	 * @param inBizFlowRouteVo
	 * @return
	 */
	@RequestMapping(value="/biz/flow/route", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody BizFlowRouteVO inBizFlowRouteVo) {		
		int outputVo = bizFlowRouteService.updateByPk(inBizFlowRouteVo);
		return getResponseData(outputVo);

	}

	/**
	 * 新增数据
	 * @param inBizFlowRouteVo
	 * @return
	 */
	@RequestMapping(value="/biz/flow/route", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertBizFlowRoute(@RequestBody BizFlowRouteVO inBizFlowRouteVo) {
		int outputVo = bizFlowRouteService.insertBizFlowRoute(inBizFlowRouteVo);
		return getResponseData(outputVo);

	}
}
